New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

x2js

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

x2js

Transforms between XML string and JavaScript object trees.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

x2js

This is a library that converts between XML and JavaScript objects. The conversion is not necessarily lossless but it is very convenient.

npm version

masterdevelopment
Build StatusBuild Status

Integration

The code is all contained within the x2js.js file, so you can include it directly via a script tag. It will create window.X2JS, which is a constructor that can be used to create instances of the converter, providing an optional configuration object.

In a Node app, require("x2js") will give you the constructor that you can use the same way.

Loading via AMD-capable loaders (e.g. require.js) is also supported and works equivalently.

The xmldom package is a dependency but it is only used under Node, as in browsers the browser DOM is used.

Quick start

var x2js = new X2JS();
var document = x2js.xml2js(xml);

console.log(document.MyRootElement.ElementX[1].toString());

var xml = x2js.js2xml(document);
console.log(xml);

See the code within x2js.js for information about what configuration options you can pass. Exported functions are listed at the end of the file - there are only a few of them.

Automated tests

A set of QUnit test cases are part of the project and act as the primary usage examples.

Run karma start --single run to test with Chrome, Firefox and IE. Run node_modules\.bin\qunit-cli all_tests.js to test with the Node runtime. Run npm test to execute both sets of tests.

Travis CI uses npm travistest to run tests using Firefox via Karma and Node.

Keywords

FAQs

Package last updated on 18 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc